package com.open.launcher.helper;



import android.content.Context;

import com.open.launcher.activity.Contast;
import com.open.launcher.bean.MarqueeBean;
import com.open.launcher.bean.RequestDto;
import com.open.launcher.callback.IRequestCallback;
import com.open.launcher.callback.IRequestLisenter;
import com.open.launcher.utils.Consts;
import com.open.launcher.utils.OkGoUtil;
import com.open.launcher.utils.Paths;
import com.open.library.utils.PreferencesUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wendal on 2017/11/2.
 */

public class NoticHelper {
    private IRequestCallback callBack;
    private List<MarqueeBean> marqueeBeen;
    private Context context;

    public NoticHelper() {
        marqueeBeen = new ArrayList<>();
    }

    public void setCallback(IRequestCallback callback) {
        this.callBack = callback;
    }
    public void loadData(String url) {
        String marUrl = "http://"+ PreferencesUtils.getString(context, Consts.IP_ADDR_KEY) + Paths.NOTIC_PAHT;
        OkGoUtil<MarqueeBean> okGoUtil = new OkGoUtil<MarqueeBean>(MarqueeBean.class, OkGoUtil.TYPE_ARRAY, new IRequestLisenter() {
            @Override
            public void onSuccessData(RequestDto dto) {
                marqueeBeen = (List<MarqueeBean>) dto.getList();
                if(marqueeBeen.size()==1){
                    Contast.HOME_MARQUEE = marqueeBeen.get(0).getContent();
                }else if(marqueeBeen.size()==2){
                    Contast.HOME_MARQUEE = marqueeBeen.get(0).getContent();
                    Contast.CHANNEL_MARQUEE = marqueeBeen.get(1).getContent();
                }
                if (callBack != null) {
                    callBack.onLoadComplete("", 0, marqueeBeen.size(), marqueeBeen);
                }
            }

            @Override
            public void onErrer(int code, String errMsg) {
            }
        });
        okGoUtil.requestGet(marUrl);
    }
}
